package algorithm_demo.leetcode;

/**
 * 100. 相同的树
 * https://leetcode.cn/problems/same-tree/
 * @author Api
 * @date 2023/4/30 16:47
 */
public class Problem_100_SameTree {

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public static boolean isSameTree(TreeNode p, TreeNode q){
        if((p == null && q != null) || (p != null && q == null)){
            return false;
        }
        if (p == null && q == null){
            return true;
        }
        return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right,q.right);
    }
}
